package com.belizer.threadCommunicate;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.Pipe;

/**
 * Created by zhaoyang on 2016/10/10.
 */
public class Thread03 implements Runnable {
    private Pipe pipe;

    public Thread03(Pipe pipe){
        this.pipe=pipe;
    }

    public void run() {
        Pipe.SourceChannel sourceChannel=pipe.source();
        ByteBuffer byteBuffer=ByteBuffer.allocate(1024);
        byteBuffer.clear();
        try {
            sourceChannel.read(byteBuffer);
            byteBuffer.flip();
            while(byteBuffer.hasRemaining()){
                System.out.print(new String (new byte[]{byteBuffer.get()},"utf-8"));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
